package org.weather.data.pojo;

/**
 * Created by syf on 2018/6/21.
 */

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.weather.data.common.ConstKey;
import org.weather.data.utils.HttpNetRequest;
import redis.clients.jedis.Jedis;

import java.util.HashMap;
import java.util.Map;

/**
 * 定时器请求接口逻辑
 */
@Component
public class RequestTask {

//    @Scheduled(cron = "0/5****?")
//    public void urlTask(){
//
//        System.out.println("时间定时器");
//    }


    public String requestUrl(String city) throws Exception{

        String url = "https://free-api.heweather.com/s6/weather/forecast?";
        Map<String,String> map = new HashMap<String, String>();
        map.put("key","bd22cbb21df2495a82029663a846baff");
        map.put("location",city);

        //请求接口
        String result = HttpNetRequest.netLoad(url,map);
        System.out.println("结果"+result + "完成");

        //存储到redis里面
        if (result != null){
            Jedis jedis = new Jedis("127.0.0.1");
            jedis.set(ConstKey.REDIS_THREE_TEN_WEATHER_KEY,result);
        }

        return result;
    }
}
